package com.gao.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gao.domain.Product;
import com.gao.service.ProductService;
import com.gao.service.impl.ProductServiceImpl;

/**
 * Servlet implementation class ShowProductDetailServlet
 */
@WebServlet("/ProductDetailServlet")
public class ProductDetailServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String idStr = request.getParameter("id");
		System.out.println("?????????id="+idStr);
		int id = Integer.parseInt(idStr);
		
		ProductService productService = new ProductServiceImpl();
		Product product=null;
		product = productService.findProductById(id);
		System.out.println(product);
		
		request.setAttribute("product", product);	
		request.getRequestDispatcher("detail.jsp").forward(request, response);
		
		
	}

}
